// 打印整个页面
// 打印页面局部
// 使用插件
// import {
//   useRouter,
//   useRoute,
//   Router,
//   RouteLocationNormalizedLoaded
// } from 'vue-router'
import { getLodop } from '@/utils/LodopFuncs'

// const lodop = getLodop()

/**
 * @description: 使用浏览器自带打印整个页面
 * @param {string} id
 * @return {*}
 */
export function printByBrowser(id?: string): void {
  // @Todo: 部分元素打印 刷新页面问题未解决
  // const router: Router = useRouter()
  // const route: RouteLocationNormalizedLoaded = useRoute()
  const dom = id ? document.getElementById(id) : null
  const body = document.body
  if (dom) body.innerHTML = dom.innerHTML
  window.print()
  // if (id) {
  //   setTimeout(() => {
  //     router.push(route.path)
  //   }, 5000)
  // }
}
/**
 * @description: 打印整个页面
 * @param {*} top
 * @param {*} left
 * @param {*} width
 * @param {*} height
 * @return {*}
 */
export function printAllPage(
  isPreview = true,
  top = 0,
  left = 0,
  width = 210,
  height = '95%'
) {
  const lodop = getLodop()
  if (lodop) {
    lodop.ADD_PRINT_HTM(
      top,
      left,
      width,
      height,
      document.body.innerHTML.toString()
    )
    if (isPreview) lodop.PREVIEW()
    else lodop.PRINT()
  }
}
/**
 * @description: 打印部分元素
 * @param {*} ref
 * @return {*}
 */
// @Note: ref元素应该传入要打印元素的父元素
export function print(
  ref: HTMLInputElement | null,
  isPreview: true,
  top = 0,
  left = 0,
  width = 210,
  height = '95%'
) {
  const lodop = getLodop()
  const strHtml = ref?.innerHTML
  lodop.ADD_PRINT_HTM(top, left, width, height, strHtml)
  if (isPreview) lodop.PREVIEW()
  else lodop.PRINT()
}
// export { printByBrowser, printAllPage, print }
